//
//  FnInsertAd.m
//  flutter_fn_sdk
//
//  Created by xiaomin huang on 2022/7/4.
//

#import "FnInsertAd.h"
#import "FnSdkHeader.h"

@interface FnInsertAd ()<FNLoadInterstitialAdDelegate>

@property (strong, nonatomic) FNInitalizeInterstitial *interstitialAd;

@end

@implementation FnInsertAd

+(instancetype)loadAdWithAppId:(NSString *)appId adsId:(NSString *)adsId isRelease:(BOOL)release{
    return [[FnInsertAd alloc] initWithAppId:appId adsId:adsId isRelease:release];
}

- (instancetype)initWithAppId:(NSString *)appId adsId:(NSString *)adsId isRelease:(BOOL)release
{
    self = [super init];
    if (self) {
        self.interstitialAd = [[FNInitalizeInterstitial alloc] initWithPlacementId:appId adsId:adsId];
        self.interstitialAd.isRelease = release;
        self.interstitialAd.delegate = self;
        [self.interstitialAd loadFnInterstitialAd];
        
    }
    return self;
}

/**
 *  广告预加载失败回调
 *  详解:当接收服务器返回的广告数据失败后调用该函数
 *   @param error 发生错误时会有相应的code和message
 */
- (void)fnInterstitialError:(NSError *)error{
    NSLog(@"插屏广告错误：%@", error);
    if (self.onError) {
        self.onError(error);
    }
}

/**
 *  插屏广告视图展示成功回调
 *  详解: 插屏广告展示成功回调该函数
 */
- (void)fnInterstitialShow{
    if (self.onShow) {
        self.onShow();
    }
}

/**
 *  插屏广告展示结束回调
 *  详解: 插屏广告展示结束回调该函数
 */
- (void)fnInterstitialClosed{
    if (self.onClosed) {
        self.onClosed();
    }
}


/**
 *  插屏广告点击回调
 *  详解: 插屏广告点击后回调该函数
 */
- (void)fnInterstitialClicked{
    if (self.onClicked) {
        self.onClicked();
    }
}

- (void)dealloc{
    self.interstitialAd.delegate = nil;
    NSLog(@"FnInsertAd - dealloc");
}

@end
